using UnityEngine;
using System.Collections;

public class GUIButton : GUIObject {
	
	public delegate void OnClick(Vector3 pos);
	public event OnClick OnClickCallback;
	
	float height;
	float halfHeight;
	float width;
	float halfWidth;
	Vector3 position;
	
	public void OnStart(){
		//Debug.Log("ONSTART");
		height = this.transform.localScale.y * localSize.y;
		halfHeight = height/2;
		width = this.transform.localScale.x * localSize.x;
		halfWidth = width/2;
	}
	
	public void OnClickEvent(Vector3 pos){
		if (OnClickCallback != null)
			OnClickCallback(pos);
	}
	
	public bool isPositionInsideButton(Vector3 targetPosition){
		position = this.transform.position;
		height = this.transform.localScale.y * localSize.y * transform.parent.transform.localScale.y;
		halfHeight = height/2;
		width = this.transform.localScale.x * localSize.x * transform.parent.transform.localScale.x;
		halfWidth = width/2;
	/*	
		Debug.Log("target " + targetPosition);
		Debug.Log("position " + position);
		Debug.Log("height " + height);
		Debug.Log("width " + width);
	*/	
		if (targetPosition.x > position.x-halfWidth && 
			targetPosition.x < position.x+halfWidth &&
			targetPosition.y < position.y+halfHeight &&
			targetPosition.y > position.y-halfHeight)
			return true;
		return false;
	}
	
}
